package ctgu.yao.cloud.controller;


import ctgu.yao.cloud.dto.ApplicationVO;
import ctgu.yao.cloud.dto.PageDTO;
import ctgu.yao.cloud.dto.ResultDTO;
import ctgu.yao.cloud.form.SearchForm;
import ctgu.yao.cloud.form.SearchForm2;
import ctgu.yao.cloud.po.Application;
import ctgu.yao.cloud.service.ApplicationService;
import ctgu.yao.cloud.util.ResultDTOUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author Y
 * @since 2022-08-16
 */
@RestController
@RequestMapping("/application")
public class ApplicationController {

    @Autowired
    private ApplicationService applicationService;

    @GetMapping("list/{page}/{size}")
    public ResultDTO selectlist(@PathVariable("page")Integer page, @PathVariable("size")Integer size){
        PageDTO pageDTO =this.applicationService.selectList(page,size);
        return ResultDTOUtil.success(pageDTO);
    }

    @GetMapping("/search")
    public ResultDTO search(SearchForm2 searchForm2){
        return ResultDTOUtil.success(this.applicationService.search(searchForm2));
    }

    //求职者搜索申请
    @RequestMapping("/search2/{rid}")
    public ResultDTO search2(SearchForm2 searchForm2,@PathVariable("rid")Integer rid){
        return ResultDTOUtil.success(this.applicationService.search2(searchForm2,rid));
    }

    //公司搜索申请
    @RequestMapping("/search1/{cuid}")
    public ResultDTO search1(SearchForm2 searchForm2,@PathVariable("cuid")Integer cuid){
        return ResultDTOUtil.success(this.applicationService.search1(searchForm2,cuid));
    }

    //公司查看申请
    @RequestMapping("list2/{page}/{size}/{cuid}")
    public ResultDTO selectlist2(@PathVariable("page")Integer page, @PathVariable("size")Integer size,@PathVariable("cuid") Integer cuid){
        PageDTO pageDTO =this.applicationService.selectList2(page,size,cuid);
        return ResultDTOUtil.success(pageDTO);
    }

    //求职者查看申请
    @RequestMapping("list3/{page}/{size}/{rid}")
    public ResultDTO selectlist3(@PathVariable("page")Integer page, @PathVariable("size")Integer size,@PathVariable("rid") Integer rid){
        PageDTO pageDTO =this.applicationService.selectList3(page,size,rid);
        return ResultDTOUtil.success(pageDTO);
    }

    //求职者同意时修改
    @RequestMapping("/update/{rid}/{reid}")
    public ResultDTO update(@RequestBody Application application,@PathVariable("rid")Integer rid,@PathVariable("reid")Integer reid){
        Boolean update = this.applicationService.update(application, rid, reid);
        if(!update) return ResultDTOUtil.fail();
        return ResultDTOUtil.success(null);
    }
    //求职者拒绝时修改
    @RequestMapping("/disagree/{rid}/{reid}")
    public ResultDTO disagree(@PathVariable("rid")Integer rid,@PathVariable("reid")Integer reid){
        Boolean update = this.applicationService.disagree(rid, reid);
        if(!update) return ResultDTOUtil.fail();
        return ResultDTOUtil.success(null);
    }
}
